# Copyright (C) 2006  Stephane Alnet
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# 

#
# For more information visit http://carrierclass.net/
#

use strict;
use warnings;

package CCNCore::Model::ChangeSet;
use Jifty::DBI::Schema;

use CCNCore::Record schema {

    column author_login =>
        type is 'text',
        default is defer { Jifty->web->current_user->id },
        references CCNCore::Model::User,
        is mandatory,
        is immutable,
        since '0.0.1',
        label is 'Author',
        hints is 'Login for the person who created the changeset.';

    column author_group =>
        default is defer { 'XXX Get the current group' },
        references CCNCore::Model::Groups,
        is mandatory,
        is immutable,
        since '0.0.1',
        label is 'Author Group',
        hints is 'Group of the person who created the changeset.';

    column created_on =>
        type is 'timestamp',
        default is defer { DateTime->now  },
        filters are 'Jifty::DBI::Filter::DateTime',
        since '0.0.1',
        label is 'Created On',
        hints is 'Time and date this change set was created.';

    column created_from =>
        type is 'text',
        default is defer { $ENV{REMOTE_HOST} },
        is mandatory,
        is immutable,
        since '0.0.1',
        label is 'Source',
        hints is 'The remote host the request came from.';
    
    column is_active =>
        type is 'boolean',
        default is 'TRUE',
        is mandatory,
        valid_values are
            { display => 'Yes', value => 'TRUE' },
            { display => 'No',  value => 'FALSE' },
        since '0.0.1',
        label is 'Active',
        hints is 'Is the change set a valid one?';

    column is_reverted =>
        type is 'boolean',
        default is 'FALSE',
        is mandatory,
        valid_values are
            { display => 'Yes', value => 'TRUE' },
            { display => 'No',  value => 'FALSE' },
        since '0.0.1',
        label is 'Reverted',
        hints is 'Has the change set been reverted?';

    column is_applied =>
        type is 'boolean',
        default is 'FALSE',
        is mandatory,
        valid_values are
            { display => 'Yes', value => 'TRUE' },
            { display => 'No',  value => 'FALSE' },
        since '0.0.1',
        label is 'Applied',
        hints is 'Has the change set been applied (after policy)?';

    column table_name =>
        type is 'varchar(64)',
        is mandatory,
        is immutable,
        since '0.0.1',
        label is 'Table name',
        hints is 'The name of the SQL table this change set applies to.';

    column operation =>
        type is 'char(1)',
        valid_values are
            { value => 'i', display => 'Insertion' },
            { value => 'm', display => 'Modification' },
        is mandatory,
        is immutable,
        since '0.0.1',
        label is 'Operation type',
        hints is 'The type of operation performed by this change set.';

    column the_id =>
        is mandatory,
        is immutable,
        since '0.0.1',
        label is 'Identifier of the record to insert or modify.',
        hints is 'The ID field of the record to insert or modify.';
};

# Your model-specific methods go here.

sub since { 0.0.1 }

1;
